import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";

var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _class, _class2;

/**
 * Message -系统消息、平台公告
 * @date: 2019-08-28
 */
import React from 'react';
import { connect } from 'dva';
import intl from 'utils/intl';
import { Link, routerRedux } from 'dva/router';
import { Bind } from 'lodash-decorators';
import { Tabs, Icon, Spin } from 'antd';
import formatterCollections from 'utils/intl/formatterCollections';
import System from "./System";
import styles from "./index.less?modules";
import Announcement from "./Announcement";
import Notification from "./Notification";
var Message = (_dec = connect(function (_ref) {
  var messageCard = _ref.messageCard,
      loading = _ref.loading;
  return {
    messageCard: messageCard,
    sysLoading: loading.effects['messageCard/cpaasQueryUserMessage'],
    noticeLoading: loading.effects['messageCard/cpaasQueryAnnouncement']
  };
}), _dec2 = formatterCollections({
  code: ['cmsg.cards']
}), _dec3 = Bind(), _dec4 = Bind(), _dec5 = Bind(), _dec6 = Bind(), _dec7 = Bind(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_React$Component) {
  _inherits(Message, _React$Component);

  var _super = _createSuper(Message);

  function Message(props) {
    var _this;

    _classCallCheck(this, Message);

    _this = _super.call(this, props);
    _this.state = {
      tabBar: 'message'
    };
    return _this;
  }
  /**
   * 查询系统消息
   */


  _createClass(Message, [{
    key: "handleUserMessage",
    value: function handleUserMessage(type) {
      var dispatch = this.props.dispatch;
      dispatch({
        type: 'messageCard/cpaasQueryUserMessage',
        payload: {
          readFlag: 0,
          userMessageTypeCode: type,
          size: 10
        }
      });
    }
    /**
     * 查询平台公告
     */

  }, {
    key: "handleAnnouncementList",
    value: function handleAnnouncementList() {
      var dispatch = this.props.dispatch;
      dispatch({
        type: 'messageCard/cpaasQueryAnnouncement',
        payload: {
          receiverTypeCode: 'ANNOUNCE',
          size: 10,
          page: 0,
          statusCode: 'PUBLISHED',
          sort: 'publishedDate,DESC',
          userNotice: true
        }
      });
    }
    /**
     *标记已读
     * @param {number} number
     * @param {string} type
     * @memberof Message
     */

  }, {
    key: "handleRead",
    value: function handleRead(number) {
      var dispatch = this.props.dispatch;
      dispatch({
        type: 'messageCard/cpaasChangeRead',
        payload: {
          userMessageIdList: number,
          readAll: 0
        }
      });
    }
    /**
     * 标签栏附加内容的显示
     */

  }, {
    key: "handleCallback",
    value: function handleCallback(key) {
      this.setState({
        tabBar: key
      });
    }
    /**
     * 跳转到详情界面
     * @param {number} record
     * @param {'message' | 'announce'} type
     */

  }, {
    key: "handleDetails",
    value: function handleDetails(record, type) {
      var dispatch = this.props.dispatch;
      var gotoUrl = "/cmsg/user-message/detail/".concat(type, "/").concat(record);
      dispatch(routerRedux.push(gotoUrl));
    }
  }, {
    key: "render",
    value: function render() {
      var _this2 = this;

      var _this$props = this.props,
          _this$props$sysLoadin = _this$props.sysLoading,
          sysLoading = _this$props$sysLoadin === void 0 ? false : _this$props$sysLoadin,
          _this$props$noticeLoa = _this$props.noticeLoading,
          noticeLoading = _this$props$noticeLoa === void 0 ? false : _this$props$noticeLoa,
          _this$props$messageCa = _this$props.messageCard;
      _this$props$messageCa = _this$props$messageCa === void 0 ? {} : _this$props$messageCa;
      var _this$props$messageCa2 = _this$props$messageCa.systemMessageList,
          systemMessageList = _this$props$messageCa2 === void 0 ? [] : _this$props$messageCa2,
          _this$props$messageCa3 = _this$props$messageCa.announcementList,
          announcementList = _this$props$messageCa3 === void 0 ? [] : _this$props$messageCa3,
          _this$props$messageCa4 = _this$props$messageCa.notificationList,
          notificationList = _this$props$messageCa4 === void 0 ? [] : _this$props$messageCa4;
      var tabBar = this.state.tabBar;
      var systemProps = {
        systemMessageList: systemMessageList,
        handleUserMessage: this.handleUserMessage,
        handleRead: this.handleRead,
        handleDetails: this.handleDetails
      };
      var announcementProps = {
        announcementList: announcementList,
        handleAnnouncementList: this.handleAnnouncementList,
        handleDetails: this.handleDetails
      };
      var notificationProps = {
        notificationList: notificationList,
        handleUserMessage: this.handleUserMessage,
        handleRead: this.handleRead,
        handleDetails: this.handleDetails
      };
      var operations = /*#__PURE__*/React.createElement("div", {
        className: styles['tab-right']
      }, tabBar === 'message' && /*#__PURE__*/React.createElement("div", {
        className: styles['tab-right-content']
      }, /*#__PURE__*/React.createElement(Link, {
        to: "/cmsg/user-message/list"
      }, intl.get('cmsg.cards.message.messageCenter').d('消息中心'), /*#__PURE__*/React.createElement(Icon, {
        type: "double-right",
        className: styles['tab-icon-padding']
      })), /*#__PURE__*/React.createElement("a", {
        onClick: function onClick() {
          return _this2.handleUserMessage('MSG');
        },
        className: styles['tab-a']
      }, intl.get('cpaas.common.button.reload').d('重新加载'), /*#__PURE__*/React.createElement(Icon, {
        type: "reload",
        className: styles['tab-icon-padding']
      }))), tabBar === 'notification' && /*#__PURE__*/React.createElement("div", {
        className: styles['tab-right-content']
      }, /*#__PURE__*/React.createElement(Link, {
        to: "/cmsg/user-message/list"
      }, intl.get('cmsg.cards.message.messageCenter').d('消息中心'), /*#__PURE__*/React.createElement(Icon, {
        type: "double-right",
        className: styles['tab-icon-padding']
      })), /*#__PURE__*/React.createElement("a", {
        onClick: function onClick() {
          return _this2.handleUserMessage('NOTICE');
        },
        className: styles['tab-a']
      }, intl.get('cpaas.common.button.reload').d('重新加载'), /*#__PURE__*/React.createElement(Icon, {
        type: "reload",
        className: styles['tab-icon-padding']
      }))), tabBar === 'announcement' && /*#__PURE__*/React.createElement("div", {
        className: styles['tab-right-content']
      }, /*#__PURE__*/React.createElement(Link, {
        to: "/cmsg/user-message/list"
      }, intl.get('cmsg.cards.message.messageCenter').d('消息中心'), /*#__PURE__*/React.createElement(Icon, {
        type: "double-right",
        className: styles['tab-icon-padding']
      })), /*#__PURE__*/React.createElement("a", {
        onClick: function onClick() {
          return _this2.handleAnnouncementList();
        },
        className: styles['tab-a']
      }, intl.get('cpaas.common.button.reload').d('重新加载'), /*#__PURE__*/React.createElement(Icon, {
        type: "reload",
        className: styles['tab-icon-padding']
      }))));
      return /*#__PURE__*/React.createElement(Tabs, {
        tabBarExtraContent: operations,
        size: "large",
        tabBarGutter: 0,
        onChange: this.handleCallback,
        className: styles.height,
        animated: false,
        defaultActiveKey: "message"
      }, /*#__PURE__*/React.createElement(Tabs.TabPane, {
        tab: intl.get('cmsg.cards.message.stationMessages').d('站内消息'),
        key: "message",
        className: styles.message
      }, /*#__PURE__*/React.createElement("div", {
        className: styles['message-overflow']
      }, /*#__PURE__*/React.createElement(Spin, {
        spinning: sysLoading
      }, /*#__PURE__*/React.createElement(System, systemProps)))), /*#__PURE__*/React.createElement(Tabs.TabPane, {
        tab: intl.get('cmsg.cards.message.systemNotification').d('系统通知'),
        key: "notification",
        className: styles.notification
      }, /*#__PURE__*/React.createElement("div", {
        className: styles['notification-overflow']
      }, /*#__PURE__*/React.createElement(Spin, {
        spinning: sysLoading
      }, /*#__PURE__*/React.createElement(Notification, notificationProps)))), /*#__PURE__*/React.createElement(Tabs.TabPane, {
        tab: intl.get('cmsg.cards.message.platformAnnounce').d('平台公告'),
        key: "announcement",
        className: styles.notice
      }, /*#__PURE__*/React.createElement("div", {
        className: styles['notice-overflow']
      }, /*#__PURE__*/React.createElement(Spin, {
        spinning: noticeLoading
      }, /*#__PURE__*/React.createElement(Announcement, announcementProps)))));
    }
  }]);

  return Message;
}(React.Component), (_applyDecoratedDescriptor(_class2.prototype, "handleUserMessage", [_dec3], Object.getOwnPropertyDescriptor(_class2.prototype, "handleUserMessage"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleAnnouncementList", [_dec4], Object.getOwnPropertyDescriptor(_class2.prototype, "handleAnnouncementList"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleRead", [_dec5], Object.getOwnPropertyDescriptor(_class2.prototype, "handleRead"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleCallback", [_dec6], Object.getOwnPropertyDescriptor(_class2.prototype, "handleCallback"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleDetails", [_dec7], Object.getOwnPropertyDescriptor(_class2.prototype, "handleDetails"), _class2.prototype)), _class2)) || _class) || _class);
export { Message as default };